package com.fs.system.college_admin.controller;

import com.fs.system.college_admin.domain.Given;
import com.fs.system.college_admin.service.AdminGivenService;
import com.fs.system.common.ResponseData;
import com.fs.system.student.domain.ApplicationRecord;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/adminGiven")
public class AdminGivenController {
    @Autowired
    private AdminGivenService adminGivenService;


    /**
     * 获取最近七天的学生申请待分配列表
     * @param stuIdList
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/getLatestGiven")
    public ResponseData getGiven(@RequestParam("stuIdList") List<Integer> stuIdList,
                                                @RequestParam(defaultValue = "1")Integer page,
                                                @RequestParam(defaultValue = "5")Integer size){
        PageInfo<ApplicationRecord> given = adminGivenService.getLatestGiven(stuIdList, page, size);
        return new ResponseData("200","查询成功",given);
    }

    /**
     * 查询七天前的学生申请待分配列表
     * @param stuIdList
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/getGiven")
    public ResponseData getLatestGiven(
            @RequestParam("stuIdList") List<Integer> stuIdList,
            @RequestParam(defaultValue = "1")Integer page,
            @RequestParam(defaultValue = "5")Integer size){
        PageInfo<ApplicationRecord> given = adminGivenService.getGiven(stuIdList, page, size);
        return new ResponseData("200","查询成功",given);
    }

    /**
     * 分配学生申请
     * @param recordId
     * @param teaId
     * @return
     */
    @PutMapping("/givenRecords/{recordId}")
    public ResponseData GivenRecords(@PathVariable Long recordId,@RequestParam Long teaId){
        adminGivenService.givenRecords(recordId, teaId);
        return new ResponseData("200","分配成功");
    }

    /**
     * 添加到分配记录表
     * @param given
     * @return
     */
    @PostMapping("/addGiven")
    public ResponseData addGiven(@RequestBody Given given){
        adminGivenService.addGiven(given);
        return new ResponseData("200","添加成功");
    }

    /**
     * 批量分配学生申请
     * @param recordIds
     * @param teaId
     * @return
     */
    @PutMapping("/givenBatchRecord/{teaId}")
    public ResponseData givenBatchRecord(@PathVariable Long teaId, @RequestBody List<Long> recordIds){
        adminGivenService.givenBatchRecord(recordIds, teaId);
        return new ResponseData("200","批量分配成功");
    }
}
